package leecode.q349;

import java.util.HashSet;
import java.util.Set;

public class Solution {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> res = new HashSet<>();
        Set<Integer> temp = new HashSet<>();
        for (int i : nums1) {
            temp.add(i);
        }
        for (int i : nums2) {
            if (temp.contains(i))
                res.add(i);
        }
        int[] rest = new int[res.size()];
        int index = 0;
        for (Integer re : res) {
            rest[index++] = re;
        }
        return rest;
    }
}
